/**
 * 
 */
package it.gommonauti.patenti.dao.factory;

import it.gommonauti.patenti.dao.H2DbMainQuestionDao;
import it.gommonauti.patenti.dao.MainQuestionDAO;
import it.gommonauti.patenti.exception.ApplicationException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author Francesco Stallone ( f.stallone73@gmail.com ).
 * 
 * Data Access Object factory for an H2 db type.
 *
 */
public class H2DbDAOFactory extends DAOFactory {

	public static final String DRIVER = "org.h2.Driver";

	//public static final String DBURL= "jdbc:h2:C://work//gommoapp//db//db";

	public static final String DBURL= 
	"jdbc:h2:/data/data/it.gommonauti.quiz.patente.app/db" +
    ";FILE_LOCK=FS" +
    ";PAGE_SIZE=1024" +
    ";CACHE_SIZE=8192";
	
	/**
	 * Create connection
	 * @throws ApplicationException 
	 * @throws SQLException 
	 */
	public static Connection createConnection() throws ApplicationException, SQLException {
		Connection conn = null;

		try{
			
		Class.forName(DRIVER);
		
		conn = DriverManager.getConnection(DBURL, "sa", "");
		
		} catch (ClassNotFoundException e) {
			// TODO: handle exception
		}
		return conn;
	}

	public MainQuestionDAO getMainQuestionDAO() {
		return new H2DbMainQuestionDao();
	}

}